import { ApiDelete, ApiGet, ApiPost, ApiPatch } from '@/services/request'

import type {
  ICreateListDto,
  IUpdateListDto,
  IGetListDto,
  IListItem
} from '@/stores/interfaces/list.interface'

export async function ApiGetTodoListById(id: string): Promise<IListItem> {
  return (await ApiGet('/todo/' + id))?.data ?? {}
}

export async function ApiGetTodoList(payload: IGetListDto): Promise<{
  list: IListItem[]
}> {
  return (await ApiGet('/todo', payload)).data
}

export async function ApiDeleteTodo(id: string) {
  return (await ApiDelete('/todo/' + id)).data
}

export async function ApiCreateTodo(payload: ICreateListDto) {
  return (await ApiPost('/todo', payload)).data
}

export async function ApiUpdateTodo(payload: IUpdateListDto) {
  return (await ApiPatch('/todo', payload)).data
}
